<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        * {
            margin-top: 20px;
        }
        .div {
            width: 150px;
            height: 90px;
            background-color: skyblue;
        }
        .div1 {
            width: 200px;
            height: 200px;
            background-color: orange;
        }
        .div2 {
            width: 100px;
            height: 100px;
            background-color: purple;
        }
        ul {
            width: 200px;
            height: 200px;
            background-color: #bfa;
            overflow: auto;
        }
        li {
            height: 100px;
        }
    </style>
</head>
<body>
    <div id="root">
        <!-- 1. prevent 阻止默认行为 -->
        <a href="http://www.baidu.com" @click.prevent="fn">百度一下</a>

        <!-- 2. stop 阻止冒泡 -->
        <div class="div" @click="btn">
            <button @click.stop="btn">点我</button>
        </div>

        <!-- 3. once 事件只执行一次 -->
        <button @click.once="btn">点我</button>

        <!-- 4. capture 使用事件的捕获模式 (在捕获阶段就触发事件) -->
        <div class="div1" @click.capture="div1">
            1
            <div class="div2"  @click="div2">
                2
            </div>
        </div> 

        <!-- 5. self 只有event.target是当前操作的元素才会触发函数 -->
        <div class="div" @click="btn">
            <!-- target是button按钮 -->
            <button @click="btn">点我</button>
        </div>

        <!-- 6. passive 先执行事件的默认行为，再执行回调函数 -->
        <ul @wheel="wheel">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        let vm = new Vue({
            el:'#root',
            methods: {
                fn (){
                    alert('jkl');
                },
                btn (e){
                    alert("哈哈");
                    console.log(e.target);
                },
                div1 (){
                    alert(1);
                },
                div2 (){
                    alert(2);
                },
                wheel(){
                    for(let i=0; i<10000; i++){
                        console.log('##');
                    }
                }
            },
        });
    </script>
</body>
</html>